package io;

import java.io.*;
import java.util.Scanner;

public class NoteDemo {
    public static void main(String[] args) throws IOException {






        Scanner scan = new Scanner(System.in);

        System.out.println("请输入一个文件名：");
        String fileName = scan.nextLine();
        PrintWriter pw = new PrintWriter(
                new BufferedWriter(
                        new OutputStreamWriter(
                                new FileOutputStream(fileName),"UTF-8"
                        )
                ),true
        );

        System.out.println("请输入内容，单独输入exit退出.");

        while (true){
            String line = scan.nextLine();
            if("exit".equalsIgnoreCase(line)){
                break;
            }
            pw.println(line);

//            pw.flush();
        }
        System.out.println("古德拜！！！");
        pw.close();





















//        Scanner scan = new Scanner(System.in);
//        System.out.println("请输入一个文件名:");
//        int a = scan.nextInt();
//
//        FileOutputStream fos = new FileOutputStream("jiayou.txt");
//        OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8");
//
//
//
//
//        BufferedWriter bw = new BufferedWriter(osw);
//
//        PrintWriter pw = new PrintWriter(bw);
//
//
//        String s = "exit";
//
//        while (true){
//            String t = scan.nextLine();
//        }
//
//
//
//
////        FileOutputStream fos = new FileOutputStream("osw.txt");
////        OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8");
////
////        osw.write("你在南方的艳阳里，大雪纷飞。");
////        osw.write("我在北方的寒夜里，四季如春");
////
////        System.out.println("写出完毕！");
////        osw.close();
//
////        FileOutputStream fos = new FileOutputStream("pw2.txt");
////
////        OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8");
////
////        BufferedWriter bw = new BufferedWriter(osw);
////
////        PrintWriter pw = new PrintWriter(bw);
////
////        pw.println("你好！");
////
////        pw.println("再见！");
////
////        System.out.println("写出完毕！");
////        pw.close();























    }
}
